<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

<xi:include href="master.html" />

<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title py:if="page">Edit page | Yale Club Beijing</title>
    <title py:if="not page">Add page | Yale Club Beijing</title>
    <style type="text/css">
        #editpage{
            margin-top: 20px;
            border-spacing: 5px;
        }
        #editpage td{
            vertical-align: top;
        }
        #editpage tr td:first-child{
            width: 100px;
            font-weight: bold;
            font-size: 14px;
        }
        #pagetitle, #pagesummary, #pagecontent, #pageurl{
            width: 900px;
        }
        #pagecontent{
            height: 300px;
        }
    </style>
    <script type="text/javascript" src="/static/javascript/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		/*mode : "textareas",*/
		mode: "exact",
		elements: "pagecontent",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		/*theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",*/
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		/*content_css : "/static/css/style.css",*/

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<script type="text/javascript">
    //<![CDATA[
    window.onload = function(){
        $('pageform').addEvent('submit', function(){
            validate();
            return false;
        });
        $('pagediscard').addEvent('click', function(){
            document.location = 'page';
        });
        $('pagetitle').addEvent('change', function(){
            $('pageurl').value = toURL($('pagetitle').value.clean());
        });
    }
    
    function validate(){
        if (!$("pagetitle").value){
            alert("Title can not be empty.");
            return;
        }
        if (!$('pageurl').value){
            alert("URL can not be empty.");
            return;
        }
        if (!$('pagesummary').value){
            alert("Summary can not be empty.");
            return;
        }
        if (!tinyMCE.get('pagecontent').getContent()){
            alert("Content can not be empty.");
            return;
        }
        $('pageform').submit();
    }
    //]]>
    </script>
</head>
<body>
<h1 py:if="page">Edit page</h1>
<h1 py:if="not page">Add page</h1>
<div py:if="collection">Current collection: ${collection.title}</div>
<form id="pageform" method="post" action="addpage">
<table id="editpage">
    <tr><td>Title</td><td><input type="text" id="pagetitle" name="title" value="${page.title if page else None}"/></td></tr>
    <tr><td>URL</td><td><input type="text" id="pageurl" name="url" value="${page.url if page else None}"/></td></tr>
    <tr><td>Summary</td><td><textarea id="pagesummary" name="summary">${page.summary if page else None}</textarea></td></tr>
    <tr><td>Content</td><td><textarea class="tinymce" id="pagecontent" name="content">${page.content if page else None}</textarea></td></tr>
    <tr><td></td><td><input type="submit" value="Save" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="pagediscard" type="button" value="Discard" /></td></tr>
</table>
<input py:if="page" type="hidden" name="pid" value="${page.id}" />
<input py:if="collection" type="hidden" name="cid" value="${collection.id}" />
</form>
</body>
</html>
